const GoWorker  =(monaco)=>{
 monaco.languages.setMonarchTokensProvider('go', {
    tokenizer: {
    root: [
      // Keywords
      [/\b(package|import|func|var|const|type|interface|struct|go|select|return|defer|break|continue|fallthrough|goto|range|chan|map|sync|atomic|error)\b/, 'keyword'],
      // Types
      [/\b(int|float32|float64|bool|string|byte|rune|uintptr|complex64|complex128)\b/, 'type'],
      // Identifiers (variable, function, etc.)
      [/[A-Za-z_][\w_]*/, 'identifier'],
      // Constants (e.g., numeric, string)
      [/\b\d+\b/, 'constant.numeric'],
      [/"([^"\\]|\\.)*"/, 'string'],
      // Comment single line
      [/\/\/.*$/, 'comment'],
      // Comment multi-line
      [/\/\*/, 'comment', '@comment'],
    ],
    comment: [
      [/[^/*]+/, 'comment'],
      [/\/\*/, 'comment', '@comment'],
      [/\*\//, 'comment', '@pop'],
      [/[/*]/, 'comment'],
    ]
  }
});
monaco.languages.registerCompletionItemProvider('go', {
  provideCompletionItems: (model, position) => {
    const suggestions = [
      // Go 关键字
      {
        label: 'package',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'package ',
        detail: 'Define the package name'
      },
      {
        label: 'import',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'import ',
        detail: 'Import a package'
      },
      {
        label: 'func',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'func ${1:name}(${2:params}) ${3:returnType} {\n\t$0\n}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Function declaration'
      },
      {
        label: 'var',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'var ${1:name} ${2:type} = ${3:value}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Variable declaration'
      },
      {
        label: 'const',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'const ${1:name} = ${2:value}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Constant declaration'
      },
      {
        label: 'type',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'type ${1:typeName} ${2:baseType}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Type declaration'
      },
      {
        label: 'if',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'if ${1:condition} {\n\t$0\n}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'If statement'
      },
      {
        label: 'for',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'for ${1:i := 0}; ${2:i} < ${3:10}; ${4:i++} {\n\t$0\n}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'For loop'
      },
      {
        label: 'go',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'go ${1:functionCall}()',
        detail: 'Goroutine (concurrent function execution)'
      },

      // 类型
      {
        label: 'int',
        kind: monaco.languages.CompletionItemKind.Type,
        insertText: 'int',
        detail: 'Integer type'
      },
      {
        label: 'string',
        kind: monaco.languages.CompletionItemKind.Type,
        insertText: 'string',
        detail: 'String type'
      },
      {
        label: 'bool',
        kind: monaco.languages.CompletionItemKind.Type,
        insertText: 'bool',
        detail: 'Boolean type'
      },

      // 常用函数
      {
        label: 'fmt.Println',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'fmt.Println(${1:args})',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Print to console'
      },
      {
        label: 'fmt.Printf',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'fmt.Printf("${1:format}", ${2:args})',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Formatted print to console'
      },
      {
        label: 'len',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'len(${1:value})',
        detail: 'Get length of a collection (slice, array, string)'
      },
      {
        label: 'cap',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'cap(${1:value})',
        detail: 'Get capacity of a slice'
      },
      {
        label: 'make',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'make(${1:map|slice|chan}, ${2:size})',
        detail: 'Create a new collection'
      },
      {
        label: 'new',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'new(${1:type})',
        detail: 'Create a new value of a given type'
      },

      // **数组与切片方法**
      {
        label: 'append',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'append(${1:slice}, ${2:value})',
        detail: 'Append an element to a slice'
      },
      {
        label: 'copy',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'copy(${1:dest}, ${2:src})',
        detail: 'Copy elements from one slice to another'
      },
      {
        label: 'cap',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'cap(${1:slice})',
        detail: 'Get the capacity of a slice'
      },
      {
        label: 'len',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'len(${1:slice})',
        detail: 'Get the length of a slice'
      },

      // **字符串方法**
      {
        label: 'len',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'len(${1:string})',
        detail: 'Get the length of a string'
      },
      {
        label: 'strings.Contains',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.Contains(${1:string}, ${2:substr})',
        detail: 'Check if a string contains a substring'
      },
      {
        label: 'strings.ToUpper',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.ToUpper(${1:string})',
        detail: 'Convert a string to uppercase'
      },
      {
        label: 'strings.ToLower',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.ToLower(${1:string})',
        detail: 'Convert a string to lowercase'
      },
      {
        label: 'strings.TrimSpace',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.TrimSpace(${1:string})',
        detail: 'Trim leading and trailing spaces from a string'
      },
      {
        label: 'strings.Split',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.Split(${1:string}, ${2:delimiter})',
        detail: 'Split a string by a delimiter and return a slice'
      },
      {
        label: 'strings.Join',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.Join(${1:slice}, ${2:delimiter})',
        detail: 'Join a slice of strings into a single string with a delimiter'
      },
      {
        label: 'strings.Replace',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strings.Replace(${1:string}, ${2:old}, ${3:new}, ${4:n})',
        detail: 'Replace occurrences of a substring in the string'
      },

      // **其他常用函数**
      {
        label: 'strconv.Atoi',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strconv.Atoi(${1:string})',
        detail: 'Convert string to integer'
      },
      {
        label: 'strconv.Itoa',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'strconv.Itoa(${1:int})',
        detail: 'Convert integer to string'
      },
      {
        label: 'math.Abs',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'math.Abs(${1:number})',
        detail: 'Returns the absolute value of a number'
      },
      {
        label: 'math.Max',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'math.Max(${1:number1}, ${2:number2})',
        detail: 'Returns the larger of two numbers'
      },
      {
        label: 'math.Min',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'math.Min(${1:number1}, ${2:number2})',
        detail: 'Returns the smaller of two numbers'
      },

      // **Channel 操作**
      {
        label: 'close',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'close(${1:channel})',
        detail: 'Close a channel'
      },
      {
        label: 'select',
        kind: monaco.languages.CompletionItemKind.Keyword,
        insertText: 'select {\n\t$0\n}',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: 'Select statement for working with channels'
      },

      // **错误处理**
      {
        label: 'errors.New',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'errors.New(${1:errorMessage})',
        detail: 'Create a new error'
      },
    ];
    return { suggestions };
  }
});
}
export default GoWorker;